#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\IIT.h>



static void *storeFromStruct;

static int recordNum;
void registerIIT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadIITRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerIIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(IIT_FILENAME, SIZE_IIT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreIITRecFromStruct(void *vdStruct)
{
	registerIIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetIITRec(), vdStruct, SIZE_IIT_REC);

}

void vdCopyIITRecFromStruct(void *vdStruct)
{
	registerIIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetIITRec(), SIZE_IIT_REC);

}

int	inSaveIITRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerIIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(IIT_FILENAME, SIZE_IIT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateIITRecFromStruct (void *vdStruct)
{
	int inRet;

	registerIIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(IIT_FILENAME, SIZE_IIT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

short inGetIssuerNumberFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetIssuerNumber();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((IIT_REC*)vdStruct)->inIssuerNumber;
}

void vdSetIssuerNumberFromStruct(short inIssuerNumber, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIssuerNumber(inIssuerNumber);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((IIT_REC*)vdStruct)->inIssuerNumber = inIssuerNumber;
}

char* szGetIssuerAbbrevFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetIssuerAbbrev();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((IIT_REC*)vdStruct)->szIssuerAbbrev;
}

void vdSetIssuerAbbrevFromStruct(const char* szIssuerAbbrev, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIssuerAbbrev(szIssuerAbbrev);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((IIT_REC*)vdStruct)->szIssuerAbbrev, szIssuerAbbrev, sizeof(((IIT_REC*)NULL)->szIssuerAbbrev)-1);
}

char* szGetIssuerLabelFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetIssuerLabel();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((IIT_REC*)vdStruct)->szIssuerLabel;
}

void vdSetIssuerLabelFromStruct(const char* szIssuerLabel, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIssuerLabel(szIssuerLabel);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((IIT_REC*)vdStruct)->szIssuerLabel, szIssuerLabel, sizeof(((IIT_REC*)NULL)->szIssuerLabel)-1);
}

char* szGetPANFormatFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetPANFormat();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((IIT_REC*)vdStruct)->szPANFormat;
}

void vdSetPANFormatFromStruct(const char* szPANFormat, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPANFormat(szPANFormat);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((IIT_REC*)vdStruct)->szPANFormat, szPANFormat, sizeof(((IIT_REC*)NULL)->szPANFormat)-1);
}

VS_BOOL fGetMerchExpDateFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetMerchExpDate();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((IIT_REC*)vdStruct)->fMerchExpDate;
}

void vdSetMerchExpDateFromStruct(VS_BOOL fMerchExpDate, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMerchExpDate(fMerchExpDate);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((IIT_REC*)vdStruct)->fMerchExpDate = fMerchExpDate;
}

VS_BOOL fGetCustExpDateFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetCustExpDate();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((IIT_REC*)vdStruct)->fCustExpDate;
}

void vdSetCustExpDateFromStruct(VS_BOOL fCustExpDate, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetCustExpDate(fCustExpDate);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((IIT_REC*)vdStruct)->fCustExpDate = fCustExpDate;
}

VS_BOOL fGetMerchPANFormatFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetMerchPANFormat();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((IIT_REC*)vdStruct)->fMerchPANFormat;
}

void vdSetMerchPANFormatFromStruct(VS_BOOL fMerchPANFormat, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMerchPANFormat(fMerchPANFormat);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((IIT_REC*)vdStruct)->fMerchPANFormat = fMerchPANFormat;
}

